/*************************************************************
 * File: Resource.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Feb 2, 2013
 * Description: 
 ************************************************************/

package snow.biz.security.model;

import org.apache.commons.lang.ObjectUtils;

import snow.biz.base.model.BaseEntity;
import snow.biz.system.model.User;
import snow.core.toolkit.format.Formatter;

/**
 * 系统资源
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
public class Resource extends BaseEntity<Integer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2894458227515945178L;

	private String uri; // 系统资源信息
	private String name; // 资源名称
	private String desc; // 资源描述
	private Boolean asMenu; // 是否作为菜单显示
	private Boolean asRoot; // 是否作为根节点显示
	private Boolean asLeaf; // 是否作为叶子节点显示
	private String component; // 资源组件
	private Integer sort; // 排序字段

	protected Resource() {
		super();
	}

	public Resource(User createUser, String uri, String name, String desc, String component, Integer sort) {
		super(createUser);
		this.uri = uri;
		setName(name);
		setDesc(desc);
		setComponent(component);
		setSort(sort);
	}

	public boolean equals(Object obj) {
		if (obj instanceof Resource) {
			return ObjectUtils.equals(getUri(), ((Resource) obj).getUri());
		}
		return false;
	}

	@Formatter(name = "leaf")
	public Boolean getAsLeaf() {
		return asLeaf;
	}

	public Boolean getAsMenu() {
		return asMenu;
	}

	public Boolean getAsRoot() {
		return asRoot;
	}

	public String getComponent() {
		return this.component;
	}

	public String getDesc() {
		return this.desc;
	}

	@Formatter(name = "text")
	public String getName() {
		return this.name;
	}

	public Integer getSort() {
		return this.sort;
	}

	public String getUri() {
		return this.uri;
	}

	public int hashCode() {
		return ObjectUtils.hashCode(getUri());
	}

	public void setAsLeaf(Boolean asLeaf) {
		this.asLeaf = asLeaf;
	}

	public void setAsMenu(Boolean asMenu) {
		this.asMenu = asMenu;
	}

	public void setAsRoot(Boolean asRoot) {
		this.asRoot = asRoot;
	}

	public void setComponent(String component) {
		this.component = component;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public void setUri(String uri) {
	}
}